﻿var typeid = sessionStorage.getItem("typeid")
var number = sessionStorage.getItem("number")
var zt = sessionStorage.getItem("status")
var sumber = sessionStorage.getItem("sumber")
var occupy = sessionStorage.getItem("occupy")
var tid = sessionStorage.getItem("tid")
console.log(tid)
$("#number").val(number)
$("#sumber").val(sumber)
$("#occupy").val(occupy)
let type;
let status;
if (typeid == null) {
    location.href = "/Table/TableDetialsHtml"
}

document.getElementById("tname").innerHTML = `<span style='color:var(--ZhuTiSe)'>${number}</span>编辑`;

let Status = [{
    status: 0,
    name: '空闲'
}, {
    status: 1,
    name: '占用'
}, {
    status: 2,
    name: '不可用'
    }]

Peng_Select.CreateElement("StatusSelect", Status, 'name', (res) => {
    status = res.status
}, "status", zt);


$.get("/Table/GetTableType", {}).then(res =>
{
    Peng_Select.CreateElement("TypeSelect", res.data, 'name', (res) => {
        type = res.id
    }, 'id', typeid);
})



var btnBc = function () {

    if ($("#number").val() == "") {
        Peng.Show("桌子号码不能为空", { type: 'Danger' });
    }
    if ($("#sumber").val() == "") {
        Peng.Show("总人数不能为空", { type: 'Danger' });
    }
    if ($("#occupy").val() == "") {
        Peng.Show("占用人数不能为空", { type: 'Danger' });
    }


    $.post("/Table/EditTable", {
        id: tid, number: $("#number").val(),
        type: type, status: status, sumber: $("#sumber").val(),
        occupy: $("#occupy").val() }).then(res => {
        if (res.code == 0) {
            Peng.Show(res.message, { type: 'Success' });
        } else {
            Peng.Show(res.message, { type: 'Danger' });
        }

    })
}